package com.djinfo.work.dao.impl;

import com.djinfo.work.common.dao.impl.BaseDaoImpl;
import com.djinfo.work.dao.RoleMenuDao;
import com.djinfo.work.entity.TbSysRoleMenu;
import org.springframework.stereotype.Repository;

import java.util.List;


/**
 * 角色
 */
@Repository("RoleMenuDao")
public class RoleMenuDaoImpl extends BaseDaoImpl implements RoleMenuDao {
	@Override
	public void save(TbSysRoleMenu object) {
		if (object.getPkRoleMenuId() == null) {
			super.save(object);
		} else {
			super.update(object);
		}
	}

	@Override
	public void update(TbSysRoleMenu object) {
		super.update(object);
	}

	@Override
	public void delete(TbSysRoleMenu object) {
		super.delete(object);
	}

	@Override
	public void deleteMenuByRoleId(String RoleId) {
		String hql = " delete FROM  TbSysRoleMenu where roleId = ? ";
		super.updateByHQL(hql,RoleId.toString());
	}

	@Override
	public TbSysRoleMenu selectOne(TbSysRoleMenu object) {
		return (TbSysRoleMenu)super.getByPrimaryKey(TbSysRoleMenu.class,object.getPkRoleMenuId());
	}

	@Override
	public List<TbSysRoleMenu> page(TbSysRoleMenu object, Integer pageNum, Integer pageSize) {
		String hql = " from TbSysRoleMenu where 1=1 ";
		return (List<TbSysRoleMenu>)super.pageQuery( hql,  pageNum,  pageSize);
	}

	@Override
	public Integer getAllRowCount() {
		String hql = "select count(*) from TbSysRoleMenu ";
		return super.getUniqueObject(hql).hashCode();
	}

	@Override
	public void deleteRoleMenuByMenuId(String menuId) {

		String hql = " delete FROM  TbSysRoleMenu where menuId = ? ";
		super.updateByHQL(hql,menuId);
	}
}

